import java.util.LinkedList;
import java.util.Queue;

class Solution695 {
    private int[] dx = {0,0,1,-1};
    private int[] dy = {1,-1,0,0} ; 
    private Queue<int[]> queue = new LinkedList<>() ;
    private int max = 0 ;
    private int m , n ;
    public int maxAreaOfIsland(int[][] grid) {
         m = grid.length ;
          n = grid[0].length ;
        for(int i=0 ; i < m ; i ++){
            for(int j=0 ; j < n ; j ++){
                if(grid[i][j] == 1){
                 bfs(grid , i , j) ; 
                }
            }
        }
       return max ;
    }
    private void bfs(int[][] grid , int i , int j ){
        int ret = 0 ; 
        queue.add(new int[] {i , j}) ; 
        while(!queue.isEmpty()){
             int[] arr = queue.poll() ;
             ret ++ ;
             int a = arr[0] , b = arr[1] ; 
             grid[a][b] = 0 ; 
             for(int z=0 ; z < 4 ; z ++){
                int x = a + dx[z] , y = b+dy[z] ; 
                if(x>=0 && x< m && y>=0 && y<n && grid[x][y] == 1){
                    grid[x][y] = 0 ;
                    queue.add(new int[]{x , y}) ; 
                }
             }
        }
        max = max>ret?max:ret ;
    }


}